<%@page import="com.tangdi.production.tdbase.util.MD5Util"%>
<%@page import="com.tangdi.production.mpbase.util.MapUtils"%>
<%@page import="com.tangdi.production.mpbase.util.MoneyUtils"%>
<%@page import="com.tangdi.production.mpbase.util.ObjectUtil"%>
<%@page import="com.tangdi.production.mpbase.constants.MsgCT"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

Map<String,Object> reqMap = (Map<String,Object>)request.getAttribute("reqMap");
String payType = ObjectUtil.getString(reqMap.get("payType"));
String subPayType = ObjectUtil.getString(reqMap.get("subPayType"));
String custOrdNo = ObjectUtil.getString(reqMap.get("custOrderNo"));
if(StringUtils.isEmpty(subPayType)){
	subPayType = "01";
}
String rateType = payType + subPayType;

String title = "";
if(MsgCT.RATE_TYPE_WEIXIN.equals(rateType)){//微信扫码
	title = "微信扫码支付 | 雅付支付";
}else if(MsgCT.RATE_TYPE_ZHIFUBAO.equals(rateType)){
	title = "支付宝扫码支付 | 雅付支付";
}

Map<String,Object> resMap = (Map<String,Object>)request.getAttribute("resMap");
String prdOrdNo = ObjectUtil.getString(resMap.get("prdOrdNo"));
String code = ObjectUtil.getString(resMap.get("code"));
String msg = ObjectUtil.getString(resMap.get("msg"));
String payAmt = ObjectUtil.getString(resMap.get("payAmt"));
if(StringUtils.isEmpty(payAmt)){
	payAmt = ObjectUtil.getString(reqMap.get("payAmt"));
}
String contentType = ObjectUtil.getString(resMap.get("contentType"));
String busContent = ObjectUtil.getString(resMap.get("busContent"));

String url = "";
String isconvertUrl = "0";
if(MsgCT.DATA_TYPE_STRING.equals(contentType)){
	url = busContent;
	if(StringUtils.isNotEmpty(url)){
		if(url.startsWith("weixin://") || url.startsWith("https://qr.alipay.com/")){//直连
			isconvertUrl = "1";
		}
	}
}

try{
	payAmt = MoneyUtils.toStrYuan(payAmt);
}catch(Exception e){
	
}

//创建查询Map
String signKey = ObjectUtil.getString(request.getAttribute(MsgCT.REQ_KEY_SIGN_KEY));

String version = ObjectUtil.getString(reqMap.get("version"));
String orgNo = ObjectUtil.getString(reqMap.get("orgNo"));
String custId = ObjectUtil.getString(reqMap.get("custId"));
String custOrderNo = ObjectUtil.getString(reqMap.get("custOrderNo"));
// String prdOrdNo = ObjectUtil.getString(resMap.get("prdOrdNo"));

Map<String,Object> queryMap = new TreeMap<String,Object>();
queryMap.put("version", version);
queryMap.put("orgNo", orgNo);
queryMap.put("custId", custId);
queryMap.put("custOrderNo", custOrderNo);

//得到签名元数据
String signStr = MapUtils.getSignStrByMap(queryMap, true);
String sign = MD5Util.digest(signStr + "&key=" + signKey);

%>

<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title><%=title %></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" href="<%=path%>/css/cashier/style.css" type="text/css"></link>
	<script type="text/javascript" src="<%=path%>/js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/jquery.qrcode.min.js"></script>
	<script type="text/javascript">
	
		function myrefresh() 
		{ 
			var version = "<%=version %>";
			var orgNo = "<%=orgNo %>";
			var custId = "<%=custId %>";
			var custOrderNo = "<%=custOrderNo %>";
			var prdOrdNo = "<%=prdOrdNo %>";
			var sign = "<%=sign%>";
			$.ajax({
				type : 'POST',
				url : '<%=path%>/cashier/query.ac',
				data : {version: version,orgNo:orgNo,custId: custId,custOrderNo:custOrderNo,prdOrdNo:prdOrdNo,sign:sign},
				dataType : "json",
				cache : false,
				success : function(json) {
					 alert("支付未完成，请扫码完成支付！");
				},
				error : function() {
					alert("请求失败!")
				}
			});
		} 
		
		$(function(){
			var isconvertUrl = "<%=isconvertUrl %>";
			if(isconvertUrl == "1"){
				$("#code").qrcode("<%=url %>");
			}else{
				$("#code").append("<img src='<%=url %>' />");
			}
		});
		
	</script>
	
  </head>
  <body>
    
    <!-- top -->
	<div class="top01">
		<table width="700" align="center">
			<tr>
				<td width="70%"><img src="<%=path%>/images/logo.png" border="0"
					height="50" />
				</td>
				<td width="30%" align="right">帮助中心 | <a
					href="http://prm.yafupay.com/website/index.html" target="_blank">返回平台首页</a></td>
			</tr>
		</table>
	</div>

	<!-- center -->
	<div class="top">
		<table cellpadding="0" cellspacing="0" width="800" height="50" align="center">
	   	 <tr>
	   	 	<td height="50" colspan="2" width="76%" class="font">请您及时付款，以便订单尽快处理！ 订单号： <font color="green"><%=custOrdNo %></font></td>
	   	 	<td class="font01">应付金额：<font color="red"  style="font-size:20px;"><%=payAmt %></font>&nbsp;元</td>
	   	 </tr>
	   	 </table>
	   	 <table cellpadding="0" cellspacing="0" width="800" height="400" align="center" style="background-color: #ffffff;">
	   	 <tr>
	   	 	<td height="400" width="400" align="center"><div id="code">&nbsp;</div></td>
	   	 	<td><img src="<%=path%>/images/pay_<%=payType %>.png"></img></td>
	   	 </tr>
	   	 <tr><td class="update"><img src="<%=path%>/images/chaxun.jpg" onclick="myrefresh()"></img></td></tr>
	   	</table>
	  </div>
	   	
 	
 
	<!-- bottom -->
	<div class="bottom">
	 <table cellpadding="0" cellspacing="0" width="100%" align="center">
		<tr><td class="foot">Copyright  2014-2016 雅付网络科技有限公司 All Rights Reserved 版权所有 不得转载<br>备案号： 沪ICP备16036723号</td></tr>
    </table>
	</div>
	
  </body>
</html>